﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace IPC.Communication.Framework.LogNet
{
    public class HslMessageItem
    {
        private static long IdNumber;

        public long Id
        {
            get;
            private set;
        }

        public HslMessageDegree Degree
        {
            get;
            set;
        }

        public int ThreadId
        {
            get;
            set;
        }

        public string Text
        {
            get;
            set;
        }

        public DateTime Time
        {
            get;
            set;
        }

        public string KeyWord
        {
            get;
            set;
        }

        public bool Cancel
        {
            get;
            set;
        }

        public HslMessageItem()
		{
			this.Degree = HslMessageDegree.DEBUG;
			this.Id = Interlocked.Increment(ref HslMessageItem.IdNumber);
			this.Time = DateTime.Now;
		}

        public override string ToString()
        {
            bool flag = this.Degree != HslMessageDegree.None;
            string result;
            if (flag)
            {
                bool flag2 = string.IsNullOrEmpty(this.KeyWord);
                if (flag2)
                {
                    result = string.Format("[{0}] {1:yyyy-MM-dd HH:mm:ss.fff} Thread [{2:D3}] {3}", new object[]
					{
						LogNetManagment.GetDegreeDescription(this.Degree),
						this.Time,
						this.ThreadId,
						this.Text
					});
                }
                else
                {
                    result = string.Format("[{0}] {1:yyyy-MM-dd HH:mm:ss.fff} Thread [{2:D3}] {3} : {4}", new object[]
					{
						LogNetManagment.GetDegreeDescription(this.Degree),
						this.Time,
						this.ThreadId,
						this.KeyWord,
						this.Text
					});
                }
            }
            else
            {
                result = this.Text;
            }
            return result;
        }

        public string ToStringWithoutKeyword()
        {
            bool flag = this.Degree != HslMessageDegree.None;
            string result;
            if (flag)
            {
                result = string.Format("[{0}] {1:yyyy-MM-dd HH:mm:ss.fff} Thread [{2:D3}] {3}", new object[]
				{
					LogNetManagment.GetDegreeDescription(this.Degree),
					this.Time,
					this.ThreadId,
					this.Text
				});
            }
            else
            {
                result = this.Text;
            }
            return result;
        }
    }
}
